package cn.itcast;

import java.util.ArrayList;
import java.util.List;

public class ArrayList1 {
    public static void main(String[] args) {
        //List list = new ArrayList();
        //list.add(1);
        //list.add(2.0);
        //list.add("three");
        //list.add(new Date());
        //
        //for(Object obj : list){
        //
        //}

        List<Integer> list = new ArrayList<>();
        List<String> list2 = new ArrayList<>();

        list.add(0);
        list.addAll(List.of(1, 2, 3, 4, 5));
        System.out.println(list);
        System.out.println(list.size());
        //list.clear();
        System.out.println(list.size());

        //学习ArrayList 数据结构本质
        //实例化
        ArrayList<Integer> li2 = new ArrayList<>();
        long ss = System.currentTimeMillis();
        List<Double> li1 = new ArrayList<>();
        for (int i = 0; i <= 300000; i++) {
            li1.add(0, Math.random());
        }
        long ee = System.currentTimeMillis();
        System.out.printf("List<Double> li1: %dms %n", ee - ss);

        ss = System.currentTimeMillis();
        ArrayList<Double> li3 = new ArrayList<>();
        for (int i = 0; i <= 100000; i++) {
            li3.add(0, Math.random());
        }
        ee = System.currentTimeMillis();
        System.out.printf("List<Double> li3: %dms %n", ee - ss);


        //此方式建立的List对象，是只读的。不删除清空排序添加
        List<Integer> li4 = List.of(1, 2, 3, 4, 5);
        System.out.println(li4);

        List<Integer> li5 = new ArrayList<>(List.of(11, 22, 33, 44, 55));
        li5.clear();
        System.out.println(li5);



    }
}
